<%@ tag import="com.dili.dd.gpi.service.account.ShiroUser" %>
<%@ tag import="org.apache.shiro.subject.SimplePrincipalCollection" %>
<%@ tag import="java.util.Set" %>
<%@ tag import="org.apache.shiro.subject.Subject" %>
<%@ tag import="org.apache.shiro.SecurityUtils" %>
<%@tag pageEncoding="UTF-8"%>
<%@attribute name="display"
             required="false"
             rtexprvalue="true"
             description="是否展示"
             type="java.lang.Boolean"
        %>
<%@attribute name="url"
             required="true"
             rtexprvalue="true"
             description="url"
             type="java.lang.String"
        %>
<%@attribute name="userId"
             required="false"
             rtexprvalue="true"
             description="当前页面资源的创建者"
             type="java.lang.Integer"
        %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<%

    SimplePrincipalCollection principals = (SimplePrincipalCollection)session.getAttribute("org.apache.shiro.subject.support.DefaultSubjectContext_PRINCIPALS_SESSION_KEY");
    ShiroUser primaryPrincipal = (ShiroUser)principals.getPrimaryPrincipal();
    Set<String> accessibleUrls = primaryPrincipal.getAccessibleUrls();
    if(display == null) display = Boolean.TRUE;
    display = display && accessibleUrls.contains(url);
    if(userId != null){
        display = display && primaryPrincipal.getUserId().equals(userId);
    }
    if(display){
%>
<jsp:doBody/>
<%
    }
%>